#ifndef _PRETTY_SIMPLE_ESI_ROUTER_
#define _PRETTY_SIMPLE_ESI_ROUTER_

#include <map>
#include <vector>
#include <string>
#include <regex.h>

namespace PESI {

  struct Route {
    Route(const std::string &context,
          const std::string &host,
          int port,
          const std::string &match) : _context(context), _host(host), _port(port), _match_str(match)
    {
      if( match.empty() ){
        _match_str = ".*";
      }
      regcomp(&_match, _match_str.c_str(), REG_EXTENDED); // wildcard
    }
    ~Route(){
      regfree(&_match);
    }
    const char *host()const{ return _host.c_str(); }
    int port()const{ return _port; }

    const char *match()const{ return _match_str.c_str(); }
    const char *context()const{ return _context.c_str(); }

    bool match( const char *path )const{
      return !regexec( &_match, path, 0, 0, 0 );
    }
  private:
    int _port;
    std::string _context, _host, _match_str;
    regex_t _match;
  };

  struct Router {
    Router();
    ~Router();

    bool load(const char *config_file);

  private:
    std::vector<Route*> _routes; 
  };

}

#endif
